import requests
import pytest
from api.ihrmEmpManageApi import EmpManageApi
from common.assertTools import common_assert
from common.dbTools import DBTools
from common.getHeader import get_header
from common.readJsonTools import read_json_file
from config import TEL, BASE_PATH


class TestAddEmpParams(object):
    """添加员工接口的 测试类"""

    def setup_class(self):
        # 创建 emp 实例
        self.emp = EmpManageApi()
        # 准备请求头
        self.req_header = get_header()

    def setup(self):
        """在每个普通方法执行前，自动调用"""
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    def teardown(self):
        """测试结束后，自动调用，删除这个手机号"""
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    # 准备 json文件的绝对路径
    file_name = BASE_PATH + "/data/addEmpData.json"

    # 调用函数， 读取 json文件，得到 [(),(),()] 格式的数据
    data = read_json_file(file_name)

    @pytest.mark.parametrize("desc, req_body, status_code, success, code, message", data)
    def test_add_emp(self, desc, req_body, status_code, success, code, message):
        """添加员工 通用测试方法"""

        resp = self.emp.add_emp(self.req_header, req_body)
        print(desc, "：", resp.json())

        # 断言
        common_assert(resp, status_code, success, code, message)
